package application;

import java.net.URL;
import java.util.ResourceBundle;

import base.Assignment;
import base.Manager;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;

import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.TableColumn;

public class ShowAssignmentToManagerController implements Initializable {
	@FXML
	private Button bcheckattendance;
	@FXML
	private Button bstaffinfo;
	@FXML
	private Button battendance_st;
	@FXML
	private Button bdaily_ass;
	@FXML
	private Button bbulletin;
	@FXML
	private Button blogout;
	@FXML
	private TableView<Assignment> assignmentList;
	@FXML
	private TableColumn<Assignment,String> content;
	@FXML
	private TableColumn<Assignment,String> date;
	@FXML
	private TableColumn<Assignment,String> staff;
	@FXML
	private TableColumn<Assignment,String> state;
	
	private Manager p=new Manager();
	private Main application;
	
	public void setApp(Main application)
	{
		this.application=application;
		ObservableList<TableColumn<Assignment,?>> observableList=assignmentList.getColumns();
		observableList.get(0).setCellValueFactory(new PropertyValueFactory("content"));
		observableList.get(1).setCellValueFactory(new PropertyValueFactory("date"));
		observableList.get(2).setCellValueFactory(new PropertyValueFactory("manager"));
		observableList.get(3).setCellValueFactory(new PropertyValueFactory("state"));
		assignmentList.setItems(p.getAssignment(p.getName()));
	}
	
	
	@FXML
	public void bbulletin(ActionEvent event){
		if("Manager".equals(p.getLevel())){
		    Manager m = (Manager)p;
			application.gotoaddBulletin(m);
		}
		else{
			application.gotoBulletin(p);
		}
		
	}
	
	@FXML
	public void gotoAssignment(ActionEvent event)
	{
		if("Manager".equals(p.getLevel()))
		{
			Manager m=(Manager)p;
			application.gotoaddAssignment(m);
		}
		else{
			application.gotoAssignment(p);
		}
	}
	
	@FXML
	public void bcheckattendance(ActionEvent event)
	{
		application.gotoCheckAttendance(p);	
	}
	

	@FXML
	public void bstaffinfo(ActionEvent event)
	{
		if("Manager".equals(p.getLevel()))
		{
			Manager m=(Manager)p;
			System.out.println("I'm Manager");
			application.gotoNamelist(m);
		}
		else
		{
			application.gotoStaffinfo(p);
		}
	}
	
	@FXML
	public void bdaily_ass(ActionEvent event)
	{
		if("Manager".equals(p.getLevel())){
		    Manager m = (Manager)p;
			application.gotoaddAssignment(m);
		}
		else{
			application.gotoAssignment(p);
		}
	}
	
	@FXML
	public void battendance_st(ActionEvent event){
		if("Manager".equals(p.getLevel())){
		    Manager m = (Manager)p;
			application.gotonamelist(m);
		}
		else{
			String s = String.valueOf(p.getID());
			application.gotoworkdayinfo(p, s);
		}
	}

	@Override
	public void initialize(URL arg0, ResourceBundle arg1) {
		// TODO Auto-generated method stub
		
	}

}
